package dao;

import java.util.ArrayList;
import java.util.List;

public class MultiColumnSort extends Sort {

	private List<SingleColumnSort> columnSortList = null;

	public MultiColumnSort() {
		columnSortList = new ArrayList<SingleColumnSort>();
	}

	public void addColumnSort(SingleColumnSort sort) {
		columnSortList.add(sort);
	}

	public String getSortQuery() {
		StringBuffer orderQuery = new StringBuffer("");
		if (columnSortList.size() > 0) {
			orderQuery.append(" ORDER BY ");

			for (int i = 0; i < columnSortList.size(); i++) {
				orderQuery
						.append(columnSortList.get(i).getColumnName()
								+ " "
								+ (columnSortList.get(i).getSens() == Sort.ASC_SORT ? "ASC"
										: "DESC"));
				if (i < columnSortList.size() - 1) {
					orderQuery.append(", ");
				}
			}
		}
		return orderQuery.toString();
	}

	public List<SingleColumnSort> getColumnSortList() {
		return columnSortList;
	}

	public void setColumnSortList(List<SingleColumnSort> columnSortList) {
		this.columnSortList = columnSortList;
	}
}
